{extend name="base:base-add" /}
{block name="title"}
<title>添加权限组</title>
{/block}
{block name="form"}
<form action="" method="post" class="form form-horizontal" id="form-admin-role-add">
    <div class="row clearfix">
        <div class="form-controls col-xs-8 col-sm-12">
            {notempty name="data"}
            {volist name="data" id="vo"}
            <dl class="Hui-admin-permission-list">
                <dt>
                    <label>
                        {$vo.name}
                    </label>
                </dt>
                <dd>
                    {notempty name="vo.permissions"}
                    {volist name="vo.permissions" id="i"}
                    <label>
                        {in name="$i.id" value="$plist"}
                        <input type="checkbox" value="{$i.id}" checked="checked" name="id">
                        {else /}
                        <input type="checkbox" value="{$i.id}" name="id">
                        {/in}
                        {$i.name}</label>
                    {/volist}
                    {else/}
                    {/notempty}
                </dd>
            </dl>
            {/volist}
            {else /}
            {/notempty}
        </div>
    </div>
    <input type="hidden" value="{$id}" name="id" id="id">
    <div class="row clearfix">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
            <button type="button" class="btn btn-success radius add">
                <i class="icon-ok"></i> 确定
            </button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
    $(".add").click(function () {
        var postData = {};
        var data = $("input[name='id']:checked").serializeArray();
        $.each(data, function () {
            postData[this.value] = this.name;
        });
        postData['id'] = $("#id").val();
        $.ajax({
            url: "/{$backendPrefix}/usr/permission/set/{$id}.html",
            type: "post",
            data: postData,
            "success": function (result) {
                var msgData = JSON.parse(result);
                if (msgData.status === true) {
                    layer.msg(msgData.message, {icon: 1, time: 1000}, function () {
                        window.parent.location.href = msgData.url
                    })
                } else {
                    layer.msg(msgData.message, {icon: 5, time: 2000})
                }
            }
        }, JSON);
    });
</script>
{/block}